#include <iostream>
#include <string>
#include <fstream>
#include <iostream>
#include <limits>
#include <string>
#include <cstdio>
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include "get_arg.h"


// link with -lboost_filesystem-gcc -lboost_program_options-gcc
// program_options_helper.cpp



// my functions
#define DEBUG_LEVEL 6
#include <debug_func.h>
#include <print_error.h>
#include <program_options_helper.h>

using std::ofstream;
using std::ifstream;
using std::cout;
using std::string;
using std::vector;
using std::cerr;
using namespace program_options_helper;
namespace po = boost::program_options_lg;


//_______________________________________________________________________________________

//		process_command_line_options

//				from command line
//				Created [9/13/2001]

//_______________________________________________________________________________________



bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	//
	// checked mandatory arguments
	//
	po::options_description mandatory_args("Mandatory Arguments");
	mandatory_args.add_options()
	("input_file,i", 		po::value<string>(&args.file_input)
									->set_name("FILE")
									->default_value("STDIN"),
								"FILE with tab delimited results.");





	//
	//	Optional arguments
	//
	args.optional_args.add_options()
	("kaks,k",              		"Results include Kaks")
	("ids,I",               		"Only swap identifiers in first two columns")
	("discard_identical,d",		po::bool_switch(&args.discard_identical),
									"Discard results where the two identifiers are "
									"identical.")
	("#comment,#",				po::value<string>(&args.comment_letters)
										->set_name("LETTERS")
										->default_value("#"),
									"Use one of these letters to begin a "
									"commented line.");



	args.use_results_summary();
	args.add_std_options();

	//	Parse all arguments
	//
	po::options_description all_args("");
	all_args.
			add(mandatory_args).
			add(args.optional_args);

	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv)
								.options(all_args)
								.run(), vm);
	po::notify(vm);


	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.3\n"
			"\tHistory: \n\n"
			"\tv 1.0\1"
			"14-06-2005\1"
			"Arrange IDs so that ID1 < ID2.\n"
			"\tv 1.1\1"
			"04-01-2006\1"
			"For Andreas: Hash start comment lines. Fix bugs in handling input. "
			"Upgrade to common code for sequence pair identifiers\n"
			"\tv 1.2\1"
			"15-03-2006\1"
			"Select among duplicate pairs the one with lowest e-value.\n"
			"\tv 1.3\1"
			"27-03-2006\1"
			"Comments can begin with user-defined letters. Defaults to hash '#'\n"
			);
		return false;
	}

	if (vm.count("help"))
	{
		string exe_description =
							"Takes alignment result or kaks FILES, "
							"and rearranges columns so that the identifiers in the first columns "
							"are lexicographically less than those in the second columns.\n"
							"id1 < id2. For duplicates, only the one pair with the "
							"lowest e-value is retained.\n";

		print_usage(cerr, string(*argv),    "[OPTIONS] --input_file FILE ",
							all_args, exe_description, 80);
		return false;
	}

	// test for > threshold so everything will pass
	//check_required_options(vm, mandatory_args);

	args.mode = eALIGN;
	if (vm.count("kaks"))
		args.mode = eKAKS;
	if (vm.count("ids"))
		args.mode = eIDs;
	args.open_err_log();
	return true;
}




